package hanshunping.project.chatRoom.chatClient.client.view;

import hanshunping.project.chatRoom.chatClient.client.service.MessageService;
import hanshunping.project.chatRoom.chatClient.client.service.UserService;
import hanshunping.project.chatRoom.chatClient.client.utils.Utility;

public class ChatView {
    private boolean loop =true;
    private String key = "";
    private UserService userService = new UserService();
    private MessageService messageService = new MessageService();
    public void mainMenu(){
        while(loop){
            System.out.println("=================欢迎登录网络通信系统=====================");
            System.out.println("\t\t 1 登录系统");
            System.out.println("\t\t 2 退出系统");
            System.out.print("请输入选择：");
            key = Utility.readString(1);
            switch(key){
                case "1":
                    System.out.print("请输入用户号：");
                    String userId = Utility.readString(50);
                    System.out.print("请输入密  码：");
                    String passWd = Utility.readString(50);
                    //提交user对象去服务器验证
                    if(userService.checkUser(userId,passWd)){
                        System.out.println("======用户："+userId+" 登录========");
                        secondMenu();
                    }else{
                        System.out.println("登录失败");
                    }
                    break;
                case "2":
                    loop = false;
                    break;
            }
        }
    }
    private void secondMenu(){
        while(loop){
            System.out.println("\t\t 1 显示在线用户列表");
            System.out.println("\t\t 2 群发消息");
            System.out.println("\t\t 3 私聊消息");
            System.out.println("\t\t 4 发送文件");
            System.out.println("\t\t 9 退出系统");
            System.out.print("请输入选择：");
            key = Utility.readString(1);
            switch (key){
                case "1": //在线用户列表
                    userService.onlineList();
                    break;
                case "3":
                    System.out.print("请输入接收方：");
                    String gid = Utility.readString(50);
                    System.out.print("请输入内容：");
                    String content = Utility.readString(100);
                    messageService.senMes(userService.getU().getUserId(),gid,content);
                    break;
                case "9":
                    userService.logout();
                    loop = false;
                    break;

            }
        }
    }
}
